package leetcode_day._2022._202209._2130;

/**
 * 1640.能否连接形成数组
 * 算法：哈希表
 *
 * @author yzh
 * @version 1.0
 * @date 2022/9/22 22:21
 */
public class _22_1640 {

    public boolean canFormArray(int[] arr, int[][] pieces) {
        int n = arr.length, m = pieces.length;
        int[] hash = new int[110];
        for (int i = 0; i < m; i++) hash[pieces[i][0]] = i;
        for (int i = 0; i < n; ) {
            int[] cur = pieces[hash[arr[i]]];
            int len = cur.length, idx = 0;
            while (idx < len && cur[idx] == arr[i + idx]) ++idx;
            if (idx == len) i += len;
            else return false;
        }
        return true;
    }

}
